<template>
    <div class="components_edit_modal">
        <el-dialog width="500px" :title="title" :visible.sync="state" :show-close="true" :close-on-click-modal="false">
            <el-form ref="film" :model="film" :rules="rules" label-width="95px" size="mini">

                <el-form-item label="订单状态：" prop="statusId">
                    <el-select v-model="film.statusId" filterable placeholder="请选择订单状态">
                        <el-option
                            v-for="item in options.orderStatusOptions"
                            :key="item.id"
                            :label="item.dictValue"
                            :value="item.id">
                        </el-option>
                    </el-select>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" size="small" @click="addfilm">确 定</el-button>
                <el-button @click="state = false"  size="small">关 闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {enums} from '@/constant'
    // import PlUpload from "../../../common/PlUpload"
    export default {
        // components: {
        //     "pl-upload":PlUpload
        // },
        data() {
            return {
                state: false,
                title: '',
                type:'',
                film:{
                    statusId: null,
                },
                rules: {
                },
                options:[],
            }
        },
        created() {},
        mounted() {
            this.getOrderStatus();
        },
        methods: {
            showDialog(val){
                if(this.$refs['film']!==undefined){
                    this.$refs['film'].resetFields();
                }

                if(val){
                    this.film.statusId = val.statusId;
                    this.id = val.id;
                    this.title = "修改订单状态";
                    this.type = "edit";
                }else{
                    this.title = "添加底片";
                    this.type = "add";
                }

                this.state = true;
            },
            addfilm(){
                let vm = this;
                vm.$refs.film.validate((valid) => {
                    if (valid) {

                        let submission =  ''; //提交方式

                        //选择提交方式
                        if(vm.type == 'edit'){
                            submission = 'put';
                        }else{
                            submission = 'post';
                        }
                        // 提交
                        vm.axios({
                            method: submission,
                            url: api.ordersManagement.ordersHandle.replace(/\{id\}/, vm.id)+ "/?statusId=" +  parseInt(vm.film.statusId),
                            /* data: vm.film */
                        }).then((response) => {
                            if (response.data.code == 200) {
                                vm.state = false;
                                vm.$parent.$refs.filmTable.$emit('vuetable:refresh');
                                vm.$message.success(response.data.message);
                            } else {
                                vm.$message.error(response.data.message);
                            }
                        })
                    }else{
                        return false;
                    }
                });
            },
            // 获取订单状态
            getOrderStatus(){
                let vm = this;
                vm.axios.get(api.dictionary.dictList+"?page=1&type=ORDER_STATUS").then((response) =>{
                    if (response.data.code == 200) {
                        vm.options.orderStatusOptions = response.data.data.dataList;
                    } else {
                        Message({
                            message: response.data.msg,
                            type: 'error'
                        });
                    }
                })
            },
        },

    };
</script>
<style scoped>
.dialog-footer{ text-align:center; }
.dialog-footer button{ margin: 0 10%; }
</style>